import numpy as np
from matplotlib import pyplot as plt

float_32 = {'bias_add': 0.0007551893393198649, 'conv2d': 0.0010391965707143148, 'batch_norm': 0.0024901750087738036, 'avg_pool': 0.0003685468832651774, 'max_pool': 0.000363176425298055, 'relu': 0.0003950850963592529, 'sigmoid': 0.00012169210116068522, 'softmax': 0.00014504170417785646, 'tanh': 0.00012565318743387857, 'matmul': 0.0006627236207326253, 'reduce_mean': 0.00016834553082784018, 'reduce_max': 0.00013160204887390138, 'reduce_min': 0.0001303619809, 'reduce_sum': 0.0001568952891, 'abs': 0.000107712185, 'square': 0.000170763136}
float_16 = {'bias_add': 0.0001438733736673991, 'conv2d': 0.000768955945968628, 'batch_norm': 0.0025696309407552084, 'avg_pool': 0.00034454552332560223, 'max_pool': 0.00034974010785420736, 'relu': 0.00037302406628926597, 'sigmoid': 9.686676661173502e-05, 'softmax': 0.0001233511765797933, 'tanh': 8.980766932169596e-05, 'matmul': 0.00024036955833435058, 'reduce_mean': 0.00012906034787495932, 'reduce_max': 0.00010136691729227701, 'reduce_min': 0.0001060962677, 'reduce_sum': 0.0001204013824, 'abs': 0.000102731778, 'square': 0.000128857212}
repair = {'bias_add': 2.9091227054595946e-05, 'conv2d': 1.6338581323623658, 'batch_norm': 0.009066994407269767, 'avg_pool': 0.0004004655718803406, 'max_pool': 0.006550205397605896, 'relu': 0.00019717140197753906, 'sigmoid': 9.175643920898437e-05, 'softmax': 0.00010505638122558595, 'tanh': 0.0002711033344268799, 'matmul': 0.020833619892597195, 'reduce_mean': 0.001215606963634491, 'reduce_max': 0.00020111504793167114, 'reduce_min': 0.0001957416456, 'reduce_sum': 0.000336799, 'abs': 0.000009298322026, 'square': 0.0000630617135}

x = ['bias_add', 'avg_pool', 'softmax', 'conv2d', 'batch_norm', 'max_pool',
     'relu', 'reduce_mean', 'reduce_max', 'sigmoid', 'tanh', 'matmul', 'reduce_min', 'reduce_sum', 'abs', 'square']

# plt.title('Consumed Time of Float32, Float16 and repair')

y_32 = [float_32[i]*1000 for i in x]
y_16 = [float_16[i]*1000 for i in x]
y_repair = [min(repair[i]*1000, 27) for i in x]

print(y_repair)
print(y_32)
print(y_16)

y_32 = y_32[0: 2] + y_32[3: 9] + y_32[11: 13] + y_32[14:]
y_16 = y_16[0: 2] + y_16[3: 9] + y_16[11: 13] + y_16[14:]
y_repair = y_repair[0: 2] + y_repair[3: 9] + y_repair[11: 13] + y_repair[14:]
print(y_repair)
print(y_32)
print(y_16)

x = ['op1', 'op2', 'op3', 'op4', 'op5', 'op6', 'op7', 'op8', 'op9', 'op10',
     'op11', 'op12']

line1, = plt.plot(x, y_32)
line2, = plt.plot(x, y_16)
line3, = plt.plot(x, y_repair)

# ax = plt.gca()
# ax.set_ylim(0, 27)
# ax.set_yticklabels(['0','3','6','9','12', '15', '18', '21', '', '1000+'], fontsize=7)

plt.xlabel("Op(s)", fontsize=9,labelpad=-1)
plt.ylabel("Time(ms)", fontsize=9, labelpad=3)
new_ticks = np.linspace(0, 27, 10)
plt.yticks(new_ticks, ['0','3','6','9','12', '15', '18', '21', '...', '1633'], fontsize=9)
plt.xticks(fontsize=8, x=x, rotation=330)

plt.legend(handles=[line1, line2, line3], labels=['GPU FP32', 'GPU FP16', 'Repair Time'],
           loc='upper right', fontsize=9)

plt.savefig('./plott/time2.eps', format='eps', dpi=1000)
plt.show()
